home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-01 | 1.5 KB | 70 lines | [TEXT/DWat] |
- % A demonstration of curve fitting
- % in Asymptote.
-
- % Fit a damped sine function
- % y = a1*exp(-a0*x)*sin(a2*x + a3).
-
- % Open the data file and read x and y
- datafile Damped Sine Data
- datalines 2
- readcolumn x 1
- readcolumn y 2
- rpn 3 >e % Set all the errors to 3
- hidewindow \f
- fullscreen on
- % Find the limits and plot the data with error bars
- graphlimits
- pointsize 4
- pointsymbol 4 filled
- plotpoints
- % Draw a frame and label the axes
- drawframe
- ploterrors top
- ploterrors bottom
- scale 1.5
- drawylabel K\d1e\\u-\sat\\dsin(\swt + \sf)
- drawxlabel t
-
- % Fit the function
- % y = a1*exp(-a0*x)*sin(a2*x + a3)
- % where x is in degrees
-
- % Parameter initial values:
- set a0 0.15 % exponential factor
- set a0fixed no
- set a1 80 % exponential amp.
- set a1fixed no
- set a2 10 % sine frequency
- set a2fixed no
- set a3 0 % sine phase
- set a3fixed no
-
- % Specify that we want to see each iteration
- set plot_each_fit yes
-
- % Fit the function
- fitxy 4 a0 x * chs e^x a1 * x a2 * a3 + deg sin *
-
- % Calculate the fit at each x
- rpn a0 <x * chs e^x a1 * <x a2 * a3 + deg sin * >y
-
- % Plot the fit on top of the data with a thicker pen
- pensize 1
- plotline
-
- % Move to the bottom right corner of the graph (this is a macro)
- BR
- % Draw the label a bit bigger
- scale 1.25
- % Use 3 significant digits for labels
- digits 3
- % Label the plot with the fit results
- drawlabel centerleft \sa:\a0 \sw:\a2 \sf:\a3 K\d1:\a1 \sc\u2:\chisq
- % Draw a title including the name of the data file and the date
- fontsize 14
- drawtitle Curve Fit To '\f' on \#
-
- % Close the Data Window
- closewindow \f
-
- fullscreen no